﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace eGrocery.CustomerDAL
{
    public class CustomerDAL
    {
    //    public override CustomerEntity.Customer SaveObject(string userName, CustomerEntity.Customer tObject)
    //    {
    //        try
    //        {
    //            GetNewDBHelper();
    //            dbHelper.AddParameter("@Customer_ID", tObject.CustomerID);
    //            dbHelper.AddParameter("@Customer_Name", tObject.CustomerName);
    //            dbHelper.AddParameter("@Customer_Age", tObject.CustomerAge);
    //            dbHelper.AddParameter("@Customer_Address", tObject.CustomerAddress);
    //            dbHelper.AddParameter("@Customer_Mobile", tObject.CustomerMobile);
    //            dbHelper.AddParameter("@Customer_AlterMobile", tObject.CustomerAlterMobile);
    //            dbHelper.AddParameter("@CreatedBy", tObject.CustCreatedBy);
    //            dbHelper.AddParameter("@Customer_CreditLimit", tObject.CustomerCreditLimit);
    //            dbHelper.AddParameter("@Creation_Date", tObject.CustCreationDate);
    //            //dbHelper.AddParameter("@CreatedBy", tObject.ProductPrice);
    //            dbHelper.AddParameter("@ModificationDate", tObject.CustModificationDate);
    //            dbHelper.AddParameter("@ModificatedBy", tObject.CustModiBy);
    //            dbHelper.AddParameter("@IsLive", tObject.CustIsalive);
    //            object objID = dbHelper.ExecuteScaler("USP_INS_UPDATE_Customer", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);

    //            if (Convert.ToInt32(objID) > 0)
    //                tObject.CustomerID = Convert.ToInt32(objID);

    //            LogActivity(userName, string.Format("Product Saved with ID {0}", tObject.CustomerID), tObject);

    //            return tObject;

    //            //dbHelper.ExecuteNonQuery("USP_INS_UPDATE_PRODUCT", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
    //        }
    //        catch (Exception)
    //        {

    //            ////throw;
    //        }
    //        return tObject;
    //        //throw new NotImplementedException();
    //    }
    //    public override List<CustomerEntity.Customer> SearchObject(string userName, string SearchText)
    //    {
    //        #region PROCEDURE
    //        /**
    //        CREATE PROCEDURE [dbo].[USP_SEARCH_CUSTOMER_NAME]  
    //            (@SearchText VARCHAR(256))  
    //            AS 
    //            SELECT  
    //            Customer_ID,
    //            Customer_Name,
    //            Customer_Mobile,
    //            ISLIVE
    //            FROM Customer
    //             where IsLive=1 and (Customer_Name LIKE '%'+ @SearchText+'%'  
    //             or Customer_ID LIKE '%'+ @SearchText+'%'
    //             or Customer_Mobile LIKE  @SearchText+'%')  
    //             order by Customer_Name 
             
    //         **/

    //        #endregion

    //        try
    //        {
    //            dbHelper.AddParameter("@SearchText", string.IsNullOrWhiteSpace(SearchText) ? string.Empty : SearchText);
    //            var reader = dbHelper.ExecuteReader("USP_SEARCH_CUSTOMER_NAME", System.Data.CommandType.StoredProcedure, System.Data.ConnectionState.Closed);
    //            var list = new List<Customer>();
    //            while (reader.Read())
    //            {
    //                list.Add(GetProductObject(reader, true));
    //            }
    //            LogActivity(userName, string.Format("Searched customer with text {0}", SearchText), null);
    //            return list;
    //        }
    //        catch (Exception ex)
    //        {
    //            LogException(userName, ex, null);
    //            throw new Exception("Error while searching Customer");
    //        }
    //        // throw new NotImplementedException();
    //    }

    //    private Customer GetProductObject(System.Data.Common.DbDataReader reader, bool p)
    //    {
    //        int i = -1;
    //        Customer obj = new Customer();
    //        if (!reader.IsDBNull(++i))
    //            obj.CustomerID = reader.GetInt32(i);
    //        if (!reader.IsDBNull(++i))
    //            obj.CustomerName = reader.GetString(i);
    //        if (!reader.IsDBNull(++i))
    //            obj.CustomerMobile = reader.GetString(i);
            
    //        return obj;
    //    }


    //    public override bool DeleteObject(string userName, Customer tObject)
    //    {
    //        throw new NotImplementedException();
    //    }

    //    public override List<Customer> GetObjectList(string userName, DateTime fromDate, DateTime toDate)
    //    {
    //        throw new NotImplementedException();
    //    }
    }
}
